package com.singzi.javaSenior.threads.basic;

import java.lang.Thread;

public class threadTest2 {
    public static void main(String[] args) {
        Windows1 windows1 = new Windows1();
        Thread  thread1 = new Thread(windows1);
        Thread  thread2 = new Thread(windows1);
        Thread  thread3 = new Thread(windows1);
        thread1.start();
        thread2.start();
        thread3.start();

    }

}
class Windows1 implements Runnable{

    final Object obj = new Object();
    private int tickets = 100;
    @Override
    public void run() {
        while (true){
            synchronized (obj){
                if(tickets > 0){
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "卖票， 票号： "+ tickets);
                    tickets --;
                }
                else {
                    break;
                }
            }
        }


    }
}